package sel.me.spring.boot245.web.domain.base;


import sel.me.spring.boot245.web.exception.UnifyStrErrorCode;

public class Result<T> extends UnifyResult<T> {

	private static final long serialVersionUID = -9075544910442561812L;

	public Result() {
		super();
	}
	
	public Result(T result) {
		super(result);
	}

	public Result(String code, String msg) {
		super(code, msg);
	}

	public Result(String code, String msg, T result) {
		super(code, msg, result);
	}

	@Override
	public Result setError(String code, String msg) {
		super.setError(code, msg);
		return this;
	}

	@Override
	public Result setResult(T result) {
		super.setResult(result);
		return this;
	}

	@Override
	public Result setCode(String code) {
		super.setCode(code);
		return this;
	}

	@Override
	public Result setMsg(String msg) {
		super.setMsg(msg);
		return this;
	}

	public String getResultCode() {
		return getCode();
	}

	public String getResultMsg() {
		return getMsg();
	}

	public static Result create(String code, String msg, Object data) {
		return new Result(code, msg, data);
	}

	public static Result create(String code, String msg) {
		return new Result(code, msg);
	}

	public static Result create(Object data) {
		if (data != null && (data instanceof UnifyStrErrorCode)) {
			return new Result(((UnifyStrErrorCode) data).getErrorCode(), ((UnifyStrErrorCode) data).getErrorMsg());
		} else {
			return new Result(data);
		}
	}

}
